package com.carreirati.evaluation;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import com.carreirati.evaluation.domain.UserProfile;
import org.springframework.roo.addon.web.mvc.controller.json.RooWebJson;
import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping("/userprofiles")
@Controller
@RooWebScaffold(path = "userprofiles", formBackingObject = UserProfile.class)
@RooWebJson(jsonObject = UserProfile.class)
public class UserProfileController {
	
	
	@RequestMapping(method = RequestMethod.POST, produces = {"text/html", "*/*"})
    public String create(@Valid UserProfile userProfile, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
        if (bindingResult.hasErrors()) {
            populateEditForm(uiModel, userProfile);
            return "userprofiles/create";
        }
        uiModel.asMap().clear();
        userProfile.persist();
        userProfile.setId(userProfile.findLastUserProfileId());
        return "redirect:/userprofiles/" + encodeUrlPathSegment(userProfile.getId().toString(), httpServletRequest);
    }
}
